<script type="text/javascript">
	var $kursadd_content = $("#kursadd_content");

	$(document).ready(function () {
		var theme = 'fresh';
		$('.field_input').addClass('jqx-input');
		$('.field_input').addClass('field');
		$('.field_input').addClass('jqx-rc-all');

		var kursadd_save = $("#kursadd_save");
		var kursadd_cancel = $("#kursadd_cancel");
		var kurspost_id = $("#kurspost_id");
		var kurspost_task = $("#kurspost_task");
		var kurspost_matauang = $("#kurspost_matauang");
		var kurspost_tanggal = $("#kurspost_tanggal");
		var kurspost_jual = $("#kurspost_jual");
		var kurspost_beli = $("#kurspost_beli");

		kursadd_save.jqxButton({ theme : theme, width : '70px', height : '18px' });
		kursadd_cancel.jqxButton({ width : '70px' , height : '18px' ,theme : theme });

		kurspost_tanggal.jqxDateTimeInput({
			formatString : 'dd-MM-yyyy',
			width : 150,
			height : 25,
			theme : theme,
			enableAbsoluteSelection: true
		});
		/* function */
		kursadd_cancel.click(function(){
			$('#mainpanelcontent').empty();
			$('<img src="./images/loader.gif" style="margin:50px auto auto 390px;">').appendTo('#contents');
			$('#mainpanelcontent').load('index.php/c_kurs/kurs_load');
		});
		kursadd_save.click(function(){
			var id = "";
			var matauang = "";
			var beli = "";
			var jual = "";
			var tanggal = "";
			var task = "";

			id = kurspost_id.val();
			matauang = kurspost_matauang.val();
			tanggal = kurspost_tanggal.jqxDateTimeInput('getDate');
			tanggal = $.jqx.dataFormat.formatdate(tanggal, 'dd-MM-yyyy');
			beli = kurspost_beli.val();
			jual = kurspost_jual.val();
			task = kurspost_task.val();

			if(task == ""){
				task = "create";
			}
			$.ajax({
				type : 'POST',
				url : 'index.php/c_kurs/kurs_save',
				data : {
					id : id,
					matauang : matauang,
					tanggal : tanggal,
					beli : beli,
					jual : jual,
					task : task
				},success : function(msg){
					var result = eval(msg);
					switch(result){
						case 1:
							$('#mainpanelcontent').empty();
							$('<img src="./images/loader.gif" style="margin:50px auto auto 390px;">').appendTo('#contents');
							$('#mainpanelcontent').load('index.php/c_kurs/kurs_load');
							alert("Data berhasil disimpan");
							break;
						default:
							alert("Data gagal disimpan");
							break;
					}
				}
			});
		});

		<?php
			if(isset($dataDetail)){
		?>
			kurspost_id.val('<?php echo $dataDetail->id; ?>');
			kurspost_matauang.val('<?php echo $dataDetail->matauang; ?>');
			var arr_tgl = '<?php echo $dataDetail->tanggal; ?>'.split('-');
			var set_tgl = new Date(arr_tgl[2], (arr_tgl[1] - 1), arr_tgl[0]);
			kurspost_tanggal.jqxDateTimeInput('setDate', set_tgl);
			kurspost_beli.val('<?php echo $dataDetail->beli; ?>');
			kurspost_jual.val('<?php echo $dataDetail->jual; ?>');
			kurspost_task.val('update');
		<?php
			}
		?>

	});

</script>
<!-- Begin content -->
<div class="modal_header">
		<span>Kurs Form</span>
	</div>
<div class="modal_content">
<div id="kursadd_content">
	<input type="hidden" id="kurspost_id">
	<input type="hidden" id="kurspost_task">
	<form action="" method="post" >
		<p>
			<label>Mata Uang:</label><br/>
			<input type="text" id="kurspost_matauang" class="field_input" style="width:150px"/>
		</p>
		<br/>
		<p>
			<label>Tanggal:</label><br/>
			<div id="kurspost_tanggal"></div>
		</p>
		<br/>

		<p>
			<label>Beli:</label><br/>
			<input type="text" id="kurspost_beli" class="field_input" style="width:150px"/>
		</p>
		<br/>
		<p>
			<label>Jual:</label><br/>
			<input type="text" id="kurspost_jual" class="field_input" style="width:150px"/>
		</p>
		<br/>
		<p>
			<table align="left">
				<tr align="left">
					<td>
						<div id='kursadd_save'>
						<img style='float: left; margin: 0px;' src='./images/icons/save.gif' />
						<div style='float: left; margin-left: 4px;'>Simpan</div>
					</div>
					</td>
					<td>
						<div id='kursadd_cancel'>
						<img style='float: left; margin: 0px;' src='./images/icons/cross.gif' />
						<div style='float: left; margin-left: 4px;'>Cancel</div>
					</div>
					</td>
				</tr>
			</table>
		</p>
		<p>&nbsp;</p>
	</form>
</div>
</div>
<!-- End left column window -->